package com.molyfun.parents.activity.msg.view;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.molyfun.parents.R;
import com.molyfun.parents.activity.msg.PushNoticeActivity;
import com.molyfun.parents.push.PushMsgCacheCenter;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by william(liuchao.hit@gmail.com).
 * Date:10/18/16.
 */
public class MainCourseNoticeView extends LinearLayout implements View.OnClickListener{

    protected LayoutInflater layoutInflater;

    private Context context;

    @InjectView(R.id.notice_desc)
    TextView mNoticeDesc;
    @InjectView(R.id.notice_close)
    ImageView mNoticeClose;

    private String mDetailId;

    public MainCourseNoticeView(Context context, AttributeSet attrs, int defStyle) {
        this(context, attrs);
    }

    public MainCourseNoticeView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs);
    }

    public MainCourseNoticeView(Context context) {
        super(context);
        init(context, null);
    }

    private void init(Context context, AttributeSet attrs) {
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
        layoutInflater.inflate(R.layout.widget_course_notice_view, this);
        ButterKnife.inject(this);
        mNoticeClose.setOnClickListener(this);
        mNoticeDesc.setOnClickListener(this);
    }

    public void initData(String noticeDesc, String detailId){
        mNoticeDesc.setText(noticeDesc);
        mDetailId = detailId;
        if(TextUtils.isEmpty(noticeDesc)){
            setVisibility(View.GONE);
        }else{
            setVisibility(View.VISIBLE);
        }

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.notice_close:
                PushMsgCacheCenter.getInstance().clearMsg();
                setVisibility(View.GONE);
                break;
            case R.id.notice_desc:
                PushNoticeActivity.startActivity(getContext(), mDetailId);
                break;
        }
    }

}